package com.universal.schedule;


import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;


public class RegistActivity extends Activity {

	private EditText mUserName;
	private EditText mUserCode;
	private Button mRegist;
	private EditText muserQueryCode;
	private SharedPreferences sp;


	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_regist);
		sp = getSharedPreferences("account", Context.MODE_PRIVATE);
		findView();
		initData();
	}

	private void initData() {
		mRegist.setOnClickListener(new OnClickListener() {

			private String name;
			private String code;
			private String qcode;

			@Override
			public void onClick(View v) {
				code = mUserCode.getText().toString().trim();
				qcode = muserQueryCode.getText().toString().trim();
				name = mUserName.getText().toString().trim();
				if(!name.equals("")&&!qcode.equals("")&&!code.equals("")){
					if(qcode.equals(code)){
						sp.edit().putString("name"+name, name).commit();
						sp.edit().putString("password"+code, code).commit();
						Toast.makeText(RegistActivity.this, "注册成功", Toast.LENGTH_SHORT).show();
						finish();
					}
				}else{
					Toast.makeText(RegistActivity.this, "帐号或密码不能为空", Toast.LENGTH_SHORT).show();
				}

			}
		});

	}

	private void findView() {
		mUserName = (EditText) findViewById(R.id.user_name);
		mUserCode = (EditText) findViewById(R.id.user_code);
		muserQueryCode = (EditText) findViewById(R.id.user_query_code);
		mRegist = (Button) findViewById(R.id.register);
	}

}
